/*
 * @Descripttion:
 * @Author: voanit
 * @Date: 2022-05-15 14:37:52
 * @LastEditors: voanit
 * @LastEditTime: 2022-05-16 10:27:54
 */
// import
import request from '@/utils/request'
import { LOGIN } from '@/store/actionTypes'
import { setToken } from '@/utils/storage'
export const actionLogin = (initialValues) => {
  return async (dispatch) => {
    // 异步
    const res = await request({
      method: 'post',
      url: '/authorizations',
      data: initialValues,
    })
    console.log(res, 9)
    if (res.message === 'OK') {
      // console.log(111)
      setToken(res.data) // 做本地缓存
      
      dispatch({ type: LOGIN, payload: res.data }) // 将token存到store中
    }
  }
}
